package modelo.servicio;

import java.util.List;
import modelo.bd.dao.CompaniaDAO;
import modelo.bd.exception.DAOException;
import modelo.dominio.Compania;

public class Companias {

    private static Companias instancia;
    private CompaniaDAO dao;

    private Companias() {
        this.dao = new CompaniaDAO();
    }

    public static Companias instancia() {
        if (instancia == null) {
            instancia = new Companias();
        }
        return instancia;
    }

    @Override
    protected Object clone()
            throws CloneNotSupportedException {
        return new CloneNotSupportedException("No se puede clonar Compania.");
    }

    public List<Compania> obtener() {
        try {
            return dao.selectAll();
        } catch (DAOException e) {
            return null;
        }
    }

    public Compania obtener(String siglas) throws DAOException {
        try {
            return dao.selectWhere("CMPN_CLAVE = '" + siglas + "'").get(0);
        } catch (DAOException e) {
            return null;
        } catch (Exception e) {
            return null;
        }
    }
}
